package twentyThreePattern.create5.prototype.section1;

import java.util.Random;

public class Client {

	public static void main(String[] args) {
		AdvTemplate template = new AdvTemplate();
		Mail mail = new Mail(template);

		int max = 10;
		for (int i = 0; i < max; i++) {
			Mail mailClone = mail.clone();
			mailClone.setAppellation(getRandString(5) + " 先生（女士）");
			mailClone.setReceiver(getRandString(5) + "@" + getRandString(8) + ".com");

			// 然后发送邮件
			sendMail(mailClone);
		}
	}

	// 发送邮件
	public static void sendMail(Mail mail) {
		System.out.println("标题：" + mail.getSubject() + "\t收件人：" + mail.getReceiver() + "\t....发送成功！");
		System.out.println(mail.toString() + "\n");
	}

	// 获得指定长度的随机字符串
	public static String getRandString(int maxLength) {
		String source = "abcdefghijklmnopqrstwuvxyzABCDEFGHIJKLMNOPQRSTWUVXYZ";
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < maxLength; i++) {
			sb.append(source.charAt(random.nextInt(maxLength)));
		}

		return sb.toString();
	}
};